package org.grew.openEntity.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import org.grew.openEntity.po.logic.EditionObj;
import org.grew.openEntity.service.EditionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @Auther: Administrator
 * @Date: 2019/1/10 17:00
 * @Description:
 */
@Controller
@RequestMapping(value = "edition")
public class EditionController {


    @Autowired
    private EditionService editionService;



    @PostMapping(value = "create")
    public String createProject(@RequestParam Long projectId,@RequestParam String editionName,@RequestParam String editionContext){
        return "redirect:/edition/createPage?code="+editionService.createEdition(new EditionObj(editionName,editionContext),projectId);
    }

    @PostMapping(value = "findProjectByName",produces = "application/json")
    @ResponseBody
    public String findProjectByName(){
        List<Map<String, Object>> editions = editionService.getEditionALL();
        JSONArray proArr = JSONArray.parseArray(JSON.toJSONString(editions));
        return proArr.toJSONString();
    }

}
